package com.hx.dao;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.hx.sqliteHelper.SQLliteHelper;

public class DiaryDao {

	private SQLliteHelper  sqLiteHelper;
	
	public DiaryDao(Context context){
		this.sqLiteHelper=new SQLliteHelper(context);
	} 
	//读操作
	public String execQuery(final String sql){
		try{
			SQLiteDatabase  db=this.sqLiteHelper.getReadableDatabase();
		    Cursor cur= db.rawQuery(sql, null);
		    cur.moveToFirst();
		    StringBuffer  buffer=new StringBuffer();
		    while(!cur.isAfterLast()){
		    	buffer.append(cur.getInt(0)+"/"+cur.getString(1)+"/"+cur.getString(2)+"/"+cur.getString(3)+"/"+cur.getString(4)+"#");
		    	cur.moveToNext();
		    }
			db.close();
		return buffer.deleteCharAt(buffer.length()-1).toString();
		}catch(RuntimeException e){
			e.printStackTrace();
			return null;
		}
	}
	//写操作
	public boolean execOther(final String sql){
		try{
			SQLiteDatabase  db=this.sqLiteHelper.getWritableDatabase();
			db.execSQL(sql);
			db.close();
			return true;
		}catch(RuntimeException e){
			e.printStackTrace();
			return false;
		}
	}
	
}
